// swagger.utils.ts
import { applyDecorators, Type } from '@nestjs/common'
import {
  ApiCreatedResponse,
  ApiOkResponse,
  getSchemaPath,
} from '@nestjs/swagger'

// 创建成功响应（201）POST
export const ApiResDataPostResponse = <TModel extends Type<any>>(
  model: TModel,
  description: string = '创建成功',
) => {
  return applyDecorators(
    ApiCreatedResponse({
      description,
      schema: {
        type: 'object',
        properties: {
          code: { type: 'number', example: 200 },
          message: { type: 'string', example: 'success' },
          data: { $ref: getSchemaPath(model) },
        },
      },
    }),
  )
}
// 请求成功响应（200） GET
export const ApiResDataGetResponse = <TModel extends Type<any>>(
  model: TModel,
  description: string = '请求成功',
) => {
  return applyDecorators(
    ApiOkResponse({
      description,
      schema: {
        type: 'object',
        properties: {
          code: { type: 'number', example: 200 },
          message: { type: 'string', example: 'success' },
          data: { $ref: getSchemaPath(model) },
        },
      },
    }),
  )
}
